package com.bxait;

import jdk.nashorn.internal.runtime.logging.Logger;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;

import java.io.IOException;

/**
 * @author Chen
 * @description: 创建es索引
 * @ClassName ESTest_Client
 * @create 2023-04-08 16:16
 * @Version 1.0
 */
@Logger
public class ESTest_Index_Create {

    public static void main(String[] args) throws IOException {
        // 创建ES的客户端
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost",9200,"http"))
        );
        // 创建索引
        CreateIndexRequest request = new CreateIndexRequest("user2");
        CreateIndexResponse createIndexResponse =
                            client.indices().create(request, RequestOptions.DEFAULT);
        // 响应状态
        boolean acknowledged = createIndexResponse.isAcknowledged();

        System.out.println("创建索引-------------------------------->>> "+acknowledged);

        // 关闭es客户端
        client.close();

    }

}
